home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
daolibb
/
readme.txt
< prev
next >
Wrap
Text File
|
1999-04-16
|
21KB
|
785 lines
DaoLib 2.0 - A complete solution for real world database development.
1 - Enhancements in this version - Requirements - Getting started
2 - Introduction
3 - Core components
4 - Intermediate abstractions
5 - User interface components
6 - Tutorial and code samples
7 - Deployment
8 - Feedback - Support
9 - Reference
10 - How to purchase
1 - Enhancements in this version - Requirements - Getting started
This new version of DaoLib has been rebuilt over the wrapping classes
for DAO provided by the #import directive of Visual C++ 6.0. This means that
it makes extensive use of the built-in support for fundamental COM types and
smart pointers. All this resulted in a more stable and compatible library.
Unzip the DaoLib file maintaining the directory structure (-d). This
library requires Visual C++ 6.x installed on the development system. The
evaluation version is fully functional, with a limit of 10 controls per
dialog and an annoying reminder.
2 - Introduction
The power of the DAO interface for dealing with databases is an
undeniable fact. It provides a fast and reliable mechanism for data
management of Access and other ISAM and ODBC databases. Though it was
engineered targeting scripting languages such as Visual Basic and VBA, it
provides a dual interface, which allows straightforward C and C++ handling of
its methods and properties.
The C/C++ developer has several options:
a) Deal with COM interfaces such as DAODatabase, DAORecordset and the
like using the OS built-in OLE support. This could be tedious and error prone,
since the developer has to deal with reference counting, object releasing and
other COM annoying aspects.
b) Go up one level through a C++ proxy. Microsoft provides such a
proxy-wrapper in its DAO library. This library is rowset-oriented and provides
a valuable variable binding mechanism, but it is not the best solution for
handling record-oriented applications.
c) Use some framework which integrates the database specifics with a
user interface management. MFC-DAO is an example of this approach. The problem
here is that the integration is best suited for a Doc/View architecture, and
it adds some complexity when dealing with dialog intensive applications.
DaoLib was built with this three-level separation of concerns. It deals
with all the COM burden, such as exception handling, reference counting and
object lifespan. It provides a wrapper level you can access directly, and it
integrates to MFC with little overhead.
3 - Core components
The classes at this level are wrapped around DAO components. In
addition, you can use helper classes such as _bstr_t, _variant_t and
Currency, which encapsulate the BSTR, VARIANT and CURRENCY semantics, allowing
a very robust parameter handling. _com_error manages error handling, converting
COM error objects into C++ exceptions.
The instantiation of Dao objects was simplified through smart
constructors, many of which take no arguments or a single string object. The
enumerator semantics is replaced by a simpler indexing mechanism. The use of
the 'property' Microsoft extension allows a 'VB-like' syntax in many cases:
using Variant indexes, you can refer to a specific field as:
FieldValue[0] or as: FieldValue["CustomerID"]
In addition, the same property (if marked read/write) can be a left or right
value.
These are the core components and their mapping to DAO components:
_FieldPtr DAOField
DaoRecordset DAORecordset
DatabasePtr DAODatabase
WorkspacePtr DAOWorkspace
_DBEnginePtr DAODBEngine
ParameterPtr DAOParameter
_QueryDefPtr DAOQueryDef
_TableDefPtr DAOTableDef
_IndexPtr DAOIndex
_UserPtr DAOUser
_GroupPtr DAOGroup
_RelationPtr DAORelation
ConnectionPtr DAOConnection
PropertyPtr DAOProperty
These are the helper classes and their COM counterparts:
_bstr_t BSTR
_variant_t VARIANT
Currency CURRENCY
This has no counterparts:
_com_error Error handling through exception throwing.
4 - Intermediate abstractions
In order to connect database objects with user interface elements
such as controls, windows or dialogs, a couple of intermediate level
abstract classes must be added to the hierarchy. These are DaoWindow and
DaoControl. A windowing user interface element must inherit from DaoWindow
and a control element from DaoControl to have complete control of its
underlying database objects. They interact tightly with MFC transfer
mechanisms.
5 - User interface components
DaoLib comes with several user interface components, but its open
architecture allows you to add your own custom components. The basic
components are:
Windowing components:
DaoDialog
DaoPropSheet
DaoPropPage
Control components:
DaoEdit
DaoCheck
DaoRadio
DaoGroup
DaoCombo
DaoListCtrl
Complete components:
ListDialog
The windowing components are intended to be used as base classes of
your dialog objects. You can create regular dialogs or property pages using
the ClassWizard and then replace the base class in the declaration and add
the constructor arguments. ClassWizard will still recognize your class and
it even will use DaoDialog or DaoPropPage when adding base class references.
The control classes can be used directly. Once again, you create
control objects with ClassWizard and then replace their declaration (you can
use the 'Replace' command if you have many controls). You can manage some
attributes of the controls at declaration time, such as enabling or writing
denial.
DaoLib includes a powerful dialog-based component called ListDialog.
It manages the display of Recordset objects through a list control, naming
each header column upon the field's name and formatting the data according
to each data type. In addition, it provides complete printing support for the
list control's contents, sorting through column header clicking, keyboard
support (Insert for adding records, Delete for deleting, Enter for viewing),
and a mouse driven context menu with those same functions.
6 - Tutorial and code samples
The use of the library does not require any special skill. If you use
Visual C++ and feel comfortable with the ClassWizard, you can produce DaoLib
code immediately. The steps to follow are:
1 - You can create a project without database support, or use an
existing project. Add DaoLib2.lib to the libraries in the project settings
(Link page). Map the include path accordingly (C/C++ - Preprocessor).
2 - In the declaration of your App class, add the core #include
#include "resource.h" // main symbols
becomes:
#include "resource.h" // main symbols
#include "bordao.h"
3 - In InitInstance, add the Database initialization:
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
becomes:
try {
OpenDatabase("mydata.mdb"); //full path here, unless same
//directory as .EXE
}
catch(_com_error& e) {
Show(e);
return FALSE;
}
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
4 - Create the appropiate dialog resource. Assign each control an ID
that resembles the name of the field with which it is associated. You can
optionally add a Modify button (ID = 302). It must be the first in the
control creation order. You may also add a Enter button (ID = 301). It must
be non-visible, non-tabstop and marked as default button (unmark the OK
button).
5 - Open the ClassWizard and create the CDialog as usual. For each
control, assign a member variable (Category: Control) of the required type.
If you want to use the macros provided with DaoLib (recommended), give each
control the exact name of the corresponding field, prefixed with 'm_' (for a
field named CustomerID it should be m_CustomerID).
6 - Close the ClassWizard and go to the dialog's class declaration
(*.h file). Replace CDialog with CDaoDialog in the inheritance tag and add
two parameters to the constructor before the existing one:
class